<template>
  <div class="attendance" @mouseenter="amListShow = true" @mouseleave="amListShow = false">
    <span>考勤管理</span>
    <div class="work_area_list" v-if="amListShow">
      <span @click="openWorkTime">工作时间设定</span>
      <!-- <span>公休日查询</span> -->
      <span @click="openAttendanceRecords">考勤记录(日)</span>
      <span @click="openAttendanceRecordsMonth">考勤记录(月))</span>
    </div>
    <!-- 考勤管理--设置时间 -->
    <div
      class="attendance_work_time"
      v-if="attendance.workTime.show"
      @mouseenter="amListShow = false"
    >
      <h2>
        <span class="iconfont icon-shijian"></span>
        <span>上下班时间设置</span>
        <i class="iconfont icon-guanbi" @click="closeWorkTime"></i>
      </h2>
      <div class="attendance_content">
        <el-form :model="attendance.workTime" class="demo-form-inline">
          <el-form-item label="上午：">
            <el-time-picker
              is-range
              v-model="attendance.workTime.am"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              placeholder="选择时间范围"
              value-format="HH:mm:ss"
              step="00:00:01"
            ></el-time-picker>
          </el-form-item>
          <el-form-item label="下午：">
            <el-time-picker
              is-range
              v-model="attendance.workTime.pm"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              placeholder="选择时间范围"
              value-format="HH:mm:ss"
              step="00:00:01"
            ></el-time-picker>
          </el-form-item>
          <div class="attendance_btns">
            <el-button type="primary" @click="setWorkingHours">修 改</el-button>
            <el-button type="danger" @click="closeWorkTime">关 闭</el-button>
          </div>
        </el-form>
      </div>
    </div>
    <!-- 考勤管理--(日)记录 -->
    <div
      class="attendance_work_time attendance_records"
      v-if="attendance.records.show"
      @mouseenter="amListShow = false"
    >
      <h2>
        <span class="iconfont icon-icon-xin_kaoqinjilu"></span>
        <span>考勤记录(日)</span>
        <i class="iconfont icon-guanbi" @click="closeAttendanceRecords"></i>
      </h2>
      <div class="attendance_records_content">
        <div class="top_box">
          <el-form inline :model="attendance.records" class="demo-form-inline">
            <el-form-item label="日期：" class="minwidth230">
              <el-date-picker
                v-model="attendance.records.date"
                type="date"
                placeholder="请选择日期"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
              <!-- <el-date-picker
                v-model="attendance.records.date"
                type="month"
                placeholder="选择月">
              </el-date-picker>-->
            </el-form-item>
            <el-form-item label="社区小区：" class="minwidth230">
              <el-select v-model="attendance.records.teamValue" placeholder="请选择社区小区">
                <el-option
                  v-for="item in attendance.records.teamList"
                  :key="item.CLIENT_NO"
                  :label="item.CLIENT_NAME"
                  :value="item.CLIENT_NO"
                ></el-option>
              </el-select>
            </el-form-item>
            <div class="records_btns">
              <el-button type="primary" @click="queryAttendanceList">查 询</el-button>
              <el-button type="success" @click="exportRowExcel">导 出</el-button>
            </div>
          </el-form>
          <div class="bottom_box">
            <span>
              上午迟到：
              <span>{{attendance.amLate}}</span>
              <i></i>
            </span>
            <span>
              上午早退：
              <span>{{attendance.amLeaveEarly}}</span>
              <i></i>
            </span>
            <span>
              下午迟到：
              <span>{{attendance.pmLate}}</span>
              <i></i>
            </span>
            <span>
              下午早退：
              <span>{{attendance.pmLeaveEarly}}</span>
              <i></i>
            </span>
            <span>
              正常：
              <span>{{attendance.normal}}</span>
              <i></i>
            </span>
            <span>
              缺卡：
              <span>{{attendance.absenteeism}}</span>
              <i></i>
            </span>
            <span>
              正常率：
              <span>{{attendance.NormalRate}}</span>
              <i></i>
            </span>
            <span>
              迟到率：
              <span>{{attendance.TardinessRate}}</span>
              <i></i>
            </span>
            <span>
              早退率：
              <span>{{attendance.EarlyRate}}</span>
            </span>
          </div>
        </div>
        <div class="table_list">
          <el-table
            :data="attendance.attendanceList"
            style="width: 100%"
            fit
            border
            @cell-mouse-enter="cellMouseEnter"
            :cell-style="cellStyle"
          >
            <el-table-column prop="Name" label="姓名" align="center"></el-table-column>
            <el-table-column prop="Cleanrance" label="社区" align="center"></el-table-column>
            <el-table-column prop="Team" label="小区" align="center"></el-table-column>
            <el-table-column prop="WorkArea" label="作业范围" align="center"></el-table-column>
            <el-table-column sortable prop="SwQianRu" label="上午签入" align="center"></el-table-column>
            <el-table-column sortable prop="SwQianChu" label="上午签出" align="center"></el-table-column>
            <el-table-column sortable prop="XwQianRu" label="下午签入" align="center"></el-table-column>
            <el-table-column sortable prop="XwQianChu" label="下午签出" align="center"></el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <!-- 考勤管理--(月)记录 -->
    <div
      class="attendance_work_time attendanceMonth_records"
      v-if="attendanceMonth.records.show"
      @mouseenter="amListShow = false"
    >
      <h2>
        <span class="iconfont icon-icon-xin_kaoqinjilu"></span>
        <span>考勤记录(月)</span>
        <i class="iconfont icon-guanbi" @click="closeAttendanceRecordsMonth"></i>
      </h2>
      <div class="attendance_records_content">
        <div class="top_box">
          <el-form inline :model="attendanceMonth.records" class="demo-form-inline">
            <el-form-item label="日期：" class="minwidth230">
              <!-- <el-date-picker
                v-model="attendance.records.date"
                type="date"
                placeholder="请选择日期"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
              ></el-date-picker>-->
              <el-date-picker
                v-model="attendanceMonth.records.date"
                type="month"
                placeholder="选择月"
                format="yyyy-MM"
                value-format="yyyy-MM"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="社区小区：" class="minwidth230">
              <el-select v-model="attendanceMonth.records.teamValue" placeholder="请选择社区小区">
                <el-option
                  v-for="item in attendanceMonth.records.teamList"
                  :key="item.CLIENT_NO"
                  :label="item.CLIENT_NAME"
                  :value="item.CLIENT_NO"
                ></el-option>
              </el-select>
            </el-form-item>
            <div class="records_btns">
              <el-button type="primary" @click="queryAttendanceMonthList">查 询</el-button>
              <el-button type="success" @click="exportRowExcelMonth">导 出</el-button>
            </div>
          </el-form>
          <div class="bottom_box">
            <!-- <span>
              上午迟到：
              <span>{{attendance.amLate}}</span>
              <i></i>
            </span>
            <span>
              上午早退：
              <span>{{attendance.amLeaveEarly}}</span>
              <i></i>
            </span>
            <span>
              下午迟到：
              <span>{{attendance.pmLate}}</span>
              <i></i>
            </span>
            <span>
              下午早退：
              <span>{{attendance.pmLeaveEarly}}</span>
              <i></i>
            </span>
            <span>
              正常：
              <span>{{attendance.normal}}</span>
              <i></i>
            </span>
            <span>
              缺卡：
              <span>{{attendance.absenteeism}}</span>
              <i></i>
            </span>-->
            <span>
              正常率：
              <span>{{attendanceMonth.NormalRate}}</span>
              <i></i>
            </span>
            <span>
              迟到率：
              <span>{{attendanceMonth.TardinessRate}}</span>
              <i></i>
            </span>
            <span>
              早退率：
              <span>{{attendanceMonth.EarlyRate}}</span>
            </span>
          </div>
        </div>
        <div class="table_list">
          <el-table
            :data="attendanceMonth.attendanceList"
            style="width: 100%"
            fit
            border
            @cell-mouse-enter="cellMouseEnter"
            :cell-style="cellStyleMonth"
            @row-dblclick="CheckDetail"
          >
            <el-table-column sortable prop="VID" label="编号" align="center"></el-table-column>
            <el-table-column prop="Name" label="姓名" align="center"></el-table-column>
            <el-table-column prop="Cleanrance" label="社区" align="center"></el-table-column>
            <el-table-column prop="Team" label="小区" align="center"></el-table-column>
            <el-table-column prop="WorkArea" label="作业范围" align="center"></el-table-column>
            <!-- <el-table-column prop="WorkDate" label="日期" align="center"></el-table-column> -->
            <el-table-column sortable prop="ZC" label="正常" align="center"></el-table-column>
            <el-table-column sortable prop="CD" label="迟到" align="center"></el-table-column>
            <el-table-column sortable prop="ZT" label="早退" align="center"></el-table-column>
            <el-table-column sortable prop="SBWDK" label="上班未打卡" align="center" width="120px"></el-table-column>
            <el-table-column sortable prop="XBWDK" label="下班未打卡" align="center" width="120px"></el-table-column>
            <el-table-column sortable prop="QQ" label="缺勤" align="center"></el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <!-- 考勤管理--(月)记录-详情 -->
    <div
      class="attendance_work_time attendanceMonth_records"
      v-if="attendanceMonthDetail.records.show"
      @mouseenter="amListShow = false"
    >
      <h2>
        <span class="iconfont icon-icon-xin_kaoqinjilu"></span>
        <span>考勤记录(月)-详情</span>
        <i class="iconfont icon-guanbi" @click="closeAttendanceRecordsMonthDetail"></i>
      </h2>
      <div class="attendance_records_content">
        <div class="top_box">
          <el-form inline :model="attendanceMonthDetail.records" class="demo-form-inline">
            <div class="records_btns">
              <!-- <el-button type="primary" @click="queryAttendanceMonthList">查 询</el-button> -->
              <el-button type="success" @click="exportRowExcelMonthDetail">导 出</el-button>
            </div>
          </el-form>
          <div class="bottom_box">
            <span>
              正常率：
              <span>{{attendanceMonthDetail.NormalRate}}</span>
              <i></i>
            </span>
            <span>
              迟到率：
              <span>{{attendanceMonthDetail.TardinessRate}}</span>
              <i></i>
            </span>
            <span>
              早退率：
              <span>{{attendanceMonthDetail.EarlyRate}}</span>
            </span>
          </div>
        </div>
        <div class="table_list">
          <el-table
            :data="attendanceMonthDetail.attendanceList"
            style="width: 100%"
            fit
            border
            @cell-mouse-enter="cellMouseEnter"
            :cell-style="cellStyleDetail"
          >
            <!-- <el-table-column sortable prop="VID" label="编号" align="center"></el-table-column> -->
            <el-table-column prop="Name" label="姓名" align="center"></el-table-column>
            <el-table-column prop="Cleanrance" label="社区" align="center"></el-table-column>
            <el-table-column prop="Team" label="小区" align="center"></el-table-column>
            <el-table-column prop="WorkArea" label="作业范围" align="center"></el-table-column>
            <el-table-column prop="WorkDate" label="日期" align="center"></el-table-column>
            <el-table-column sortable prop="SwQianRu" label="上午签入" align="center"></el-table-column>
            <el-table-column sortable prop="SwQianChu" label="上午签出" align="center"></el-table-column>
            <el-table-column sortable prop="XwQianRu" label="下午签入" align="center"></el-table-column>
            <el-table-column sortable prop="XwQianChu" label="下午签出" align="center"></el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <div class="attendance_work_time2" v-if="YZT.show" @mouseenter="amListShow = false">
      <h2>
        <span class="iconfont icon-shijian"></span>
        <span>统计日期设置</span>
        <i class="iconfont icon-guanbi" @click="YZT.show=false"></i>
      </h2>
      <div class="attendance_content">
        <el-form :model="attendance.workTime" class="demo-form-inline wid100">
          <!-- <el-form-item label="上午：">
            <el-time-picker
              is-range
              v-model="attendance.workTime.am"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              placeholder="选择时间范围"
              value-format="HH:mm:ss"
              step="00:00:01"
            ></el-time-picker>
          </el-form-item>
          <el-form-item label="下午：">
            <el-time-picker
              is-range
              v-model="attendance.workTime.pm"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              placeholder="选择时间范围"
              value-format="HH:mm:ss"
              step="00:00:01"
            ></el-time-picker>
          </el-form-item>-->
          <!-- <el-radio v-model="radio" label="1">任意时间段</el-radio> -->
          <el-form-item>
            <el-radio v-model="YZT.radio" label="1" class="wid70">按日期</el-radio>
            <el-date-picker v-model="YZT.date" type="date" placeholder="选择日期"></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-radio v-model="YZT.radio" label="2">按月份</el-radio>
            <el-date-picker v-model="YZT.month" type="month" placeholder="选择月份"></el-date-picker>
            <div class="attendance_btns">
              <el-button type="primary" @click="yztTj">查 询</el-button>
              <el-button type="danger" @click="closeYZT">关 闭</el-button>
            </div>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
// 引入导出Excel函数
import export2Excel from '@/utils/exportExcel/index.js'
import MapStr from '@/main.js'
export default {
  data () {
    return {
      YZT: {
        show: false,
        date: '',
        month: '',
        radio: '1'
      },
      amListShow: false,
      // 考勤管理-日
      attendance: {
        workTime: {
          show: false,
          am: [],
          pm: [],
          ClientNo: ''
        },
        records: {
          show: false,
          date: '',
          teamValue: '',
          teamList: []
        },
        attendanceList: [],
        amLate: 0,
        amLeaveEarly: 0,
        pmLate: 0,
        pmLeaveEarly: 0,
        normal: 0,
        absenteeism: 0,
        NormalRate: 0,
        TardinessRate: 0,
        EarlyRate: 0
      },
      // 考勤管理-月
      attendanceMonth: {
        workTime: {
          show: false,
          am: [],
          pm: [],
          ClientNo: ''
        },
        records: {
          show: false,
          date: '',
          teamValue: '',
          teamList: []
        },
        attendanceList: [],
        amLate: 0,
        amLeaveEarly: 0,
        pmLate: 0,
        pmLeaveEarly: 0,
        normal: 0,
        absenteeism: 0,
        NormalRate: 0,
        TardinessRate: 0,
        EarlyRate: 0
      },
      // 考勤管理-月-详情
      attendanceMonthDetail: {
        workTime: {
          show: false,
          am: [],
          pm: [],
          ClientNo: ''
        },
        records: {
          show: false,
          date: '',
          teamValue: '',
          teamList: []
        },
        VID: 0,
        attendanceList: [],
        amLate: 0,
        amLeaveEarly: 0,
        pmLate: 0,
        pmLeaveEarly: 0,
        normal: 0,
        absenteeism: 0,
        NormalRate: 0,
        TardinessRate: 0,
        EarlyRate: 0
      },
    }
  },
  methods: {
    // 考勤管理--打开考勤记录
    // openAttendanceRecords () {
    //   // eventBus.$emit('isCover', true)
    //   this.attendance.records.show = true
    //   this.attendance.workTime.show = false
    //   this.amListShow = false
    //   this.getTeamList()
    //   this.attendance.records.teamValue = this.$route.query.ClientNo
    //   const date = new Date().toLocaleDateString().split('/')
    //   if (date[1].length === 1) date[1] = '0' + date[1]
    //   if (date[2].length === 1) date[2] = '0' + date[2]
    //   this.attendance.records.date = date.join('-')
    //   this.queryAttendanceList()
    // },
    openYZT () {
      this.YZT.show = true
    },
    closeYZT () {
      this.YZT.show = false
    },
    yztTj () {
      let user = ''
      let clientNo = `${this.$route.query.ClientNo}`
      // if (clientNo == '0000001') {
      //   user = 'glx'
      // }
      // if (clientNo == '0000004') {
      //   user = 'yx'
      // }
      user=MapStr.user
      debugger
      let dateTime = ''
      if (this.YZT.radio == "1")
        dateTime = this.dat(this.YZT.date)
      else if (this.YZT.radio == "2")
        dateTime = this.mont(this.YZT.month)
      // let date = new Date()
      // let seperator1 = "-"
      // let year = date.getFullYear()
      // let month = date.getMonth() + 1
      // if (month >= 1 && month <= 9) {
      //   month = "0" + month
      // }
      // let DateTime = year + seperator1 + month
      window.open('http://111.160.78.62:9936/indexPerson.html?user=' + user + '&&date=' + dateTime+'&&ClientNo='+clientNo, '_blank')
    },
    dat (val) {
      var year = val.getFullYear();
      var month =
        val.getMonth() + 1 > 9 ? val.getMonth() + 1 : "0" + (val.getMonth() + 1);
      var d = val.getDate();
      if (d < 10)
        d = "0" + d;
      return year + "-" + month + "-" + d;
    },
    mont (val) {
      var year = val.getFullYear();
      var month =
        val.getMonth() + 1 > 9 ? val.getMonth() + 1 : "0" + (val.getMonth() + 1);
      // var d = val.getDate();
      return year + "-" + month;
    },
    // 考勤管理--打开设定工作时间
    async openWorkTime () {
      this.attendance.workTime.show = true
      this.attendance.records.show = false
      // 获取时间
      this.attendance.workTime.am = []
      this.attendance.workTime.pm = []
      const { data } = await this.$Http.get(`/DataListCompany/GetWorkeTimeApi?ClientNo=${this.$route.query.ClientNo}`)

      if (!data[0].AM_IN.split(':')[2]) data[0].AM_IN += ':00'
      if (!data[0].AM_OUT.split(':')[2]) data[0].AM_OUT += ':00'

      this.attendance.workTime.am.push(data[0].AM_IN, data[0].AM_OUT)
      this.attendance.workTime.pm.push(data[0].PM_IN, data[0].PM_OUT)
      this.attendance.workTime.ClientNo = data[0].CLIENT_NO

      this.amListShow = false
    },
    // 考勤管理--关闭设定工作时间
    closeWorkTime () {
      this.attendance.workTime.show = false
      // eventBus.$emit('isCover', false)
    },
    // 考勤管理--设定工作时间
    setWorkingHours () {
      const params = {
        AmIn: this.attendance.workTime.am[0],
        AmOut: this.attendance.workTime.am[1],
        PmIn: this.attendance.workTime.pm[0],
        PmOut: this.attendance.workTime.pm[1],
        ClientNo: this.attendance.workTime.ClientNo
      }

      this.$Http.get('/DataListCompany/UpdateWorkerWorkTimeApi', { params })
      this.attendance.workTime.show = false
      this.$message({
        showClose: true,
        message: '修改成功！！！',
        type: 'success'
      })
    },
    // 考勤管理--打开考勤记录(日)
    openAttendanceRecords () {
      this.attendance.records.show = true
      this.amListShow = false
      this.getTeamList()
      this.attendance.records.teamValue = this.$route.query.ClientNo
      const date = new Date().toLocaleDateString().split('/')
      if (date[1].length === 1) date[1] = '0' + date[1]
      if (date[2].length === 1) date[2] = '0' + date[2]
      debugger
      this.attendance.records.date = date.join('-')
      this.queryAttendanceList()
    },
    // 考勤管理--打开考勤记录(月)
    openAttendanceRecordsMonth () {
      this.attendanceMonth.records.show = true
      this.amListShow = false
      this.getTeamList()
      this.attendanceMonth.records.teamValue = this.$route.query.ClientNo
      const date = new Date().toLocaleDateString().split('/')
      if (date[1].length === 1) date[1] = '0' + date[1]
      if (date[2].length === 1) date[2] = '0' + date[2]
      // debugger
      var myDate = new Date()
      var tYear = myDate.getFullYear()
      var tMonth = myDate.getMonth()

      var m = tMonth + 1
      if (m.toString().length == 1) {
        m = "0" + m
      }
      // return tYear +'-'+ m
      this.attendanceMonth.records.date = tYear + '-' + m
      this.queryAttendanceMonthList()
    },
    CheckDetail (row, column, event) {
      this.attendanceMonthDetail.records.show = true
      this.amListShow = false
      // this.getTeamList()
      this.attendanceMonthDetail.records.teamValue = this.$route.query.ClientNo
      // const date = new Date().toLocaleDateString().split('/')
      // if (date[1].length === 1) date[1] = '0' + date[1]
      // if (date[2].length === 1) date[2] = '0' + date[2]
      // debugger
      var myDate = new Date()
      var tYear = myDate.getFullYear()
      var tMonth = myDate.getMonth()
      var m = tMonth + 1
      if (m.toString().length == 1) {
        m = "0" + m
      }
      // return tYear +'-'+ m
      this.attendanceMonthDetail.records.date = tYear + '-' + m
      this.attendanceMonthDetail.VID = row.VID
      this.queryAttendanceMonthDetailList()
    },
    // 考勤管理--关闭考勤记录(日)
    closeAttendanceRecords () {
      this.attendance.records.show = false
      // eventBus.$emit('isCover', false)
    },
    // 考勤管理--关闭考勤记录(月)
    closeAttendanceRecordsMonth () {
      this.attendanceMonth.records.show = false
      // eventBus.$emit('isCover', false)
    },
    // 考勤管理--关闭考勤记录(月)统计
    closeAttendanceRecordsMonthDetail () {
      this.attendanceMonthDetail.records.show = false
      // eventBus.$emit('isCover', false)
    },
    // 考勤管理--班组列表
    async getTeamList () {
      const { data } = await this.$Http.get(`/DataListCompany/GetCleanerGroupListApi?ClientNo=${this.$route.query.ClientNo}`)
      this.attendance.records.teamList = data
      this.attendanceMonth.records.teamList = data
    },
    // 考勤管理--查询考勤记录列表(日)
    async queryAttendanceList () {
      const params = {
        ClientNo: this.attendance.records.teamValue,
        workDate: this.attendance.records.date
      }
      // const { data } = await this.$Http.get('/DataListCompany/GetAttendanceApi', { params })

      const { data } = await this.$Http.get('/DataListCompany/GetAttendanceDatApi', { params })
      // debugger
      this.attendance.amLate = data.status.SwCd
      this.attendance.amLeaveEarly = data.status.SwZt
      this.attendance.pmLate = data.status.XwCd
      this.attendance.pmLeaveEarly = data.status.XwZt
      this.attendance.normal = data.status.ZC
      this.attendance.absenteeism = data.status.QK
      this.attendance.NormalRate = data.attendanceStatistics.NormalRate
      this.attendance.TardinessRate = data.attendanceStatistics.TardinessRate
      this.attendance.EarlyRate = data.attendanceStatistics.EarlyRate
      // data.forEach(item => {
      //   if (item.上午签入 === '迟到') this.attendance.amLate++
      //   if (item.上午签出 === '早退') this.attendance.amLeaveEarly++
      //   if (item.下午签入 === '迟到') this.attendance.pmLate++
      //   if (item.下午签出 === '早退') this.attendance.pmLeaveEarly++
      // })

      // data.filter(item => {
      //   if (item.上午签入 === '缺卡') return this.attendance.absenteeism++
      //   if (item.上午签出 === '缺卡') return this.attendance.absenteeism++
      //   if (item.下午签入 === '缺卡') return this.attendance.absenteeism++
      //   if (item.下午签出 === '缺卡') return this.attendance.absenteeism++
      // })

      this.attendance.attendanceList = data.detailList
    },
    //考勤管理--查询考勤记录列表(月)
    async queryAttendanceMonthList () {
      const params = {
        ClientNo: this.attendanceMonth.records.teamValue,
        workDate: this.attendanceMonth.records.date
      }
      const { data } = await this.$Http.get('/DataListCompany/GetAttendanceMonthApi', { params })
      this.attendanceMonth.NormalRate = data.attendanceStatistics.NormalRate
      this.attendanceMonth.TardinessRate = data.attendanceStatistics.TardinessRate
      this.attendanceMonth.EarlyRate = data.attendanceStatistics.EarlyRate
      this.attendanceMonth.attendanceList = data.detailList
    },
    //考勤管理--查询考勤记录列表(月)
    async queryAttendanceMonthDetailList () {
      const params = {
        ClientNo: this.attendanceMonthDetail.records.teamValue,
        workDate: this.attendanceMonthDetail.records.date,
        vid: this.attendanceMonthDetail.VID
      }
      const { data } = await this.$Http.get('/DataListCompany/GetAttendanceDetailDataApi', { params })
      this.attendanceMonthDetail.NormalRate = data.attendanceStatistics.NormalRate
      this.attendanceMonthDetail.TardinessRate = data.attendanceStatistics.TardinessRate
      this.attendanceMonthDetail.EarlyRate = data.attendanceStatistics.EarlyRate
      this.attendanceMonthDetail.attendanceList = data.detailList
    },
    // 鼠标进入单元格显示其内容
    cellMouseEnter (row, column, cell, event) {
      cell.setAttribute('title', cell.innerText)
    },
    // 导出Excel
    exportRowExcel () {
      let excelName = '考勤记录信息列表(日)'
      // const tHeader = ['姓名', '社区', '小区', '作业范围', '上午签入', '上午签出', '下午签入', '下午签出']
      // const filterVal = ['姓名', '社区', '小区', '作业范围', '上午签入', '上午签出', '下午签入', '下午签出']
      const tHeader = ['姓名', '社区', '小区', '作业范围', '上午签入', '上午签出', '下午签入', '下午签出']
      const filterVal = ['Name', 'Cleanrance', 'Team', 'WorkArea', 'SwQianRu', 'SwQianChu', 'XwQianRu', 'XwQianChu']
      export2Excel(tHeader, filterVal, this.attendance.attendanceList, excelName)
    },
    // 导出Excel
    exportRowExcelMonth () {
      let excelName = '考勤记录信息列表(月)'
      // const tHeader = ['姓名', '社区', '小区', '作业范围', '上午签入', '上午签出', '下午签入', '下午签出']
      // const filterVal = ['姓名', '社区', '小区', '作业范围', '上午签入', '上午签出', '下午签入', '下午签出']
      const tHeader = ['编号', '姓名', '社区', '小区', '作业范围', '正常', '迟到', '早退', '上班未打卡', '下班未打卡', '缺勤']
      const filterVal = ['VID', 'Name', 'Cleanrance', 'Team', 'WorkArea', 'ZC', 'ZT', 'SBWDK', 'XBWDK', 'QQ']
      export2Excel(tHeader, filterVal, this.attendanceMonth.attendanceList, excelName)
    },
    // 导出Excel
    exportRowExcelMonthDetail () {
      let excelName = '考勤记录信息列表(月)-详情'
      // const tHeader = ['姓名', '社区', '小区', '作业范围', '上午签入', '上午签出', '下午签入', '下午签出']
      // const filterVal = ['姓名', '社区', '小区', '作业范围', '上午签入', '上午签出', '下午签入', '下午签出']
      const tHeader = ['姓名', '社区', '小区', '作业范围', '日期', '上午签入', '上午签出', '下午签入', '下午签出']
      const filterVal = ['Name', 'Cleanrance', 'Team', 'WorkArea', 'WorkDate', 'SwQianRu', 'SwQianChu', 'XwQianRu', 'XwQianChu']
      export2Excel(tHeader, filterVal, this.attendanceMonthDetail.attendanceList, excelName)
    },
    // 单元格样式-考勤记录(日)
    cellStyle ({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 4) {
        if (row.SwQianRu === '缺卡') return 'color: red'
        if (row.SwQianRu === '迟到') return 'color: #E6A23C'
        return 'color: #67C23A'
      }
      if (columnIndex === 5) {
        if (row.SwQianChu === '缺卡') return 'color: red'
        if (row.SwQianChu === '早退') return 'color: #E6A23C'
        return 'color: #67C23A'
      }
      if (columnIndex === 6) {
        if (row.XwQianRu === '缺卡') return 'color: red'
        if (row.XwQianRu === '迟到') return 'color: #E6A23C'
        return 'color: #67C23A'
      }
      if (columnIndex === 7) {
        if (row.XwQianChu === '缺卡') return 'color: red'
        if (row.XwQianChu === '早退') return 'color: #E6A23C'
        return 'color: #67C23A'
      }
    },
    // 单元格样式-考勤记录(月)
    cellStyleMonth ({ row, column, rowIndex, columnIndex }) {
      // if (columnIndex === 4) {
      //   if (row.SwQianRu === '缺卡') return 'color: red'
      //   if (row.SwQianRu === '迟到') return 'color: #E6A23C'
      //   return 'color: #67C23A'
      // }
      if (columnIndex === 5) {
        if (row.SwQianChu === '缺卡') return 'color: red'
        if (row.SwQianChu === '早退') return 'color: #E6A23C'
        return 'color: #67C23A'
      }
      if (columnIndex === 6) {
        return 'color: #E6A23C'
      }
      if (columnIndex === 7) {
        return 'color: #E6A23C'
      }
      if (columnIndex === 8) {
        return 'color: red'
      }
      if (columnIndex === 9) {
        return 'color: red'
      }
    },
    cellStyleDetail ({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 5) {
        if (row.SwQianRu === '缺卡') return 'color: red'
        if (row.SwQianRu === '迟到') return 'color: #E6A23C'
        return 'color: #67C23A'
      }
      if (columnIndex === 6) {
        if (row.SwQianChu === '缺卡') return 'color: red'
        if (row.SwQianChu === '早退') return 'color: #E6A23C'
        return 'color: #67C23A'
      }
      if (columnIndex === 7) {
        if (row.XwQianRu === '缺卡') return 'color: red'
        if (row.XwQianRu === '迟到') return 'color: #E6A23C'
        return 'color: #67C23A'
      }
      if (columnIndex === 8) {
        if (row.XwQianChu === '缺卡') return 'color: red'
        if (row.XwQianChu === '早退') return 'color: #E6A23C'
        return 'color: #67C23A'
      }
    },
  }
}
</script>

<style scoped lang="less">
.attendance {
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: relative;
  cursor: default;
  text-align: center;
  border-right: 2px solid #07c4a8;
  & > span:hover {
    color: #07c4a8;
  }
  .work_area_list {
    width: 130px;
    // height: 78px;
    border: 1px solid #ccc;
    background-color: #f3f3f3;
    position: absolute;
    top: 18px;
    left: -10px;
    z-index: 222222222222;
    span:last-child {
      border-bottom: 0;
    }
    span {
      display: block;
      padding: 0 10px 0 10px;
      line-height: 26px;
      color: #333;
      border-bottom: 1px solid #2ea9fa;
      &:hover {
        color: #fff;
        background-color: #2ea9fa;
      }
    }
  }
  .attendance_work_time {
    width: 600px;
    height: 260px;
    background-color: #fff;
    border: 1px solid #ccc;
    position: fixed;
    left: 50%;
    top: 130px;
    transform: translateX(-50%);
    z-index: 89;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 5px 3px #ccc;
    h2 {
      line-height: 30px;
      border-bottom: 1px solid #ccc;
      padding-left: 10px;
      color: #666;
      span {
        margin-right: 5px;
      }
      i {
        float: right;
        margin-right: 10px;
      }
    }
    .attendance_content {
      .el-form {
        width: 400px;
        margin: 50px auto;
        .el-form-item {
          margin-bottom: 30px;
        }
        /deep/.el-date-editor .el-range__icon {
          line-height: 18px;
        }
        /deep/.el-date-editor .el-range-separator {
          line-height: 18px;
        }
        /deep/.el-input__icon {
          line-height: 20px;
        }
        .attendance_btns {
          margin-top: 40px;
          text-align: center;
          .el-button {
            display: inline-block;
            padding: 0 10px;
            margin: 0 20px;
          }
        }
      }
    }
  }
  .attendance_work_time2 {
    width: 400px;
    height: 200px;
    background-color: #fff;
    border: 1px solid #ccc;
    position: fixed;
    left: 50%;
    top: 130px;
    transform: translateX(-50%);
    z-index: 89;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 5px 3px #ccc;
    h2 {
      line-height: 30px;
      border-bottom: 1px solid #ccc;
      padding-left: 10px;
      color: #666;
      span {
        margin-right: 5px;
      }
      i {
        float: right;
        margin-right: 10px;
      }
    }
    .attendance_content {
      .el-form {
        width: 400px;
        // margin: 50px auto;
        // .el-form-item {
        //   margin-bottom: 30px;
        // }
        // /deep/.el-date-editor .el-range__icon {
        //   line-height: 18px;
        // }
        // /deep/.el-date-editor .el-range-separator {
        //   line-height: 18px;
        // }
        // /deep/.el-input__icon {
        //   line-height: 20px;
        // }
        .attendance_btns {
          margin-top: 40px;
          text-align: center;
          .el-button {
            display: inline-block;
            padding: 0 10px;
            margin: 0 20px;
          }
        }
      }
    }
  }

  .attendance_records {
    width: 1000px;
    height: 498px;
    top: 50%;
    transform: translate(-50%, -50%);
    .top_box {
      height: 60px;
      padding-left: 20px;
      border-bottom: 1px solid #ccc;
      .el-form {
        margin: 5px 0;
        display: flex;
        align-items: center;
      }
      .el-form-item {
        width: 200px;
        margin: 0;
        margin-right: 20px;
        /deep/.el-date-editor.el-input {
          width: 152px;
        }
        .el-select {
          width: 152px;
        }
      }
      .records_btns {
        margin-left: 20px;
        .el-button {
          display: inline-block;
          margin-right: 20px;
          padding: 0 5px;
        }
      }
    }
    .bottom_box {
      color: #333;
      padding-top: 5px;
      & > span {
        padding-right: 5px;
        display: inline-block;
        &:last-child {
          border: 0 none;
        }
        span {
          padding: 0 2px;
          border-bottom: 1px solid #ccc;
        }
        i {
          display: inline-block;
          width: 2px;
          height: 12px;
          background-color: #999;
          margin-left: 8px;
        }
      }
    }
    .attendance_records_content {
      height: calc(~'100% - 32px');
      .table_list {
        height: calc(~'100% - 60px');
        // overflow-y: auto;
        .el-table {
          height: 100%;
          /deep/.el-table__body-wrapper {
            height: calc(~'100% - 35px');
            overflow-y: auto;
          }
        }
      }
    }
  }

  .attendanceMonth_records {
    width: 1200px;
    height: 498px;
    top: 50%;
    transform: translate(-50%, -50%);
    .top_box {
      height: 60px;
      padding-left: 20px;
      border-bottom: 1px solid #ccc;
      .el-form {
        margin: 5px 0;
        display: flex;
        align-items: center;
      }
      .el-form-item {
        width: 200px;
        margin: 0;
        margin-right: 20px;
        /deep/.el-date-editor.el-input {
          width: 152px;
        }
        .el-select {
          width: 152px;
        }
      }
      .records_btns {
        margin-left: 20px;
        .el-button {
          display: inline-block;
          margin-right: 20px;
          padding: 0 5px;
        }
      }
    }
    .bottom_box {
      color: #333;
      padding-top: 5px;
      & > span {
        padding-right: 5px;
        display: inline-block;
        &:last-child {
          border: 0 none;
        }
        span {
          padding: 0 2px;
          border-bottom: 1px solid #ccc;
        }
        i {
          display: inline-block;
          width: 2px;
          height: 12px;
          background-color: #999;
          margin-left: 8px;
        }
      }
    }
    .attendance_records_content {
      height: calc(~'100% - 32px');
      .table_list {
        height: calc(~'100% - 60px');
        // overflow-y: auto;
        .el-table {
          height: 100%;
          /deep/.el-table__body-wrapper {
            height: calc(~'100% - 35px');
            overflow-y: auto;
          }
        }
      }
    }
  }
}
.wid70 {
  max-width: 70px;
}
.wid100 {
  width: 100% !important;
}
.el-form-item {
  margin-top: 22px;
}
</style>